package com.example.myDesignPatterns.行为型模式.责任链模式Responsibility.用责任链模式处理全局异常.config;


import com.example.myDesignPatterns.行为型模式.责任链模式Responsibility.用责任链模式处理全局异常.handler.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AppConfig {
    @Bean
    public List<ExceptionHandler> exceptionHandlers() {
        List<ExceptionHandler> handlers = new ArrayList<>();
        handlers.add(new ArithmeticExceptionHandler());
        handlers.add(new IOExceptionHandler());
        handlers.add(new DefaultExceptionHandler());
        return handlers;
    }

    @Bean
    public ExceptionHandler exceptionHandlerChain(List<ExceptionHandler> handlers) {
        return new ExceptionHandlerChainBuilder(handlers).build();
    }
}